/**
 * 
 */
package com.thon.dao.project.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.thon.dao.project.ProjectRecommendDao;
import com.thon.dao.util.AbstractDao;
import com.thon.dao.util.Page;
import com.thon.entity.project.ProjectRecommend;
import com.thon.entity.user.User;

/**
 * @file ProjectRecommendDaoImpl.java
 * @author Zemo
 * @mail zemochen@gmail.com
 * @data 2013年10月11日 上午11:32:53
 * @description: TODO
 */
@Repository
public class ProjectRecommendImpl extends AbstractDao<ProjectRecommend>
		implements ProjectRecommendDao {

	public ProjectRecommendImpl() {
		super(ProjectRecommend.class);
	}

	@Override
	public Long countRecommend(int projectId) {

		String queryString = "SELECT COUNT(*) FROM ProjectRecommend pr WHERE pr.project.id = ?";
		return count(queryString, projectId);
	}

	@Override
	public List<ProjectRecommend> listRecommender(int projectId) {

		String queryString = "FROM ProjectRecommend pr WHERE pr.project.id=?";

		return findList(queryString, null, projectId);
	}

	public Page<ProjectRecommend> getProjectPage(Page<ProjectRecommend> page) {
		String queryString = "select * from ym_project_recommends order by created_date desc";
		return findPageBySql(page, queryString, null);
	}

	@Override
	public ProjectRecommend getProjectRecommend(int pid, int uid) {
		String queryString="FROM ProjectRecommend p where p.project.id=? and p.user.id=?";
		return findOne(queryString, null, pid,uid);
	}

	@Override
	public Long hasRecommend(Integer uid, Integer pid) {
		String sqlString="SELECT COUNT(*) FROM ym_project_recommends recommends WHERE recommends.user_id=? AND recommends.project_id=?";
		return countBySql(sqlString,uid,pid);
	}
}
